﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using socialnexus.classes.pages;
using socialnexus.classes.models;

namespace socialnexus.admin.Administrators
{
    public partial class Add : ProtectedPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                AdminUser au = new AdminUser();
                au.FirstName = txtFirstName.Text;
                au.LastName = txtLastName.Text;
                au.IsActive = true;
                au.Username = txtUserName.Text;
                au.Password = txtPassword.Text;
                au.Save();
            }
        }

        protected void ValidatePassword(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = (txtPassword.Text == txtPasswordConfirm.Text);
        }

        protected void ValidateUniqueUsername(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = !AdminUser.UserNameExists(txtUserName.Text);
        }
    }
}
